package com.kingbook.common.exception;

import org.slf4j.Logger;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 2015年8月7日 下午12:52:16
 * Version 1.0
 */
public class AbstractException extends RuntimeException {

	private static final long serialVersionUID = 583570023294617142L;

	public AbstractException() {
		super();
	}

	public AbstractException(String errorMsg) {
		super(errorMsg);
	}
	

	public AbstractException(String msg,Logger logger){
		super(msg);
		logger.error(msg);
	}

	public AbstractException(String msg,Exception e,Logger logger){
		super(msg,e);
		StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw =  new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            try {
                if (sw != null) 
                	sw.close();

                if (pw != null) 
                    pw.close();
                
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            
        }
		logger.error(msg);
        logger.error(sw.toString());
	}
}
